import '@nutui/nutui-react-taro/dist/style.css'
import { View } from '@tarojs/components'
import { cloud, useDidHide, useDidShow } from '@tarojs/taro'
import { useEffect } from 'react'
import './app.less'
import './assets/font/iconfont.css'
import { CLOUD_CONFIG } from './services/config'
import { onLogin } from './services/login'
import { useTabBarStore } from './stores/tabbar'
import { useUserActions } from './stores/user'

function App(props) {
  const { setUserInfo } = useUserActions()
  cloud.init({
    env: CLOUD_CONFIG.env,
  })
  const initTabBar = useTabBarStore((state) => state.initTabBar)

  useEffect(() => {
    onLogin().then((res) => {
      setUserInfo(res)
    })
    // 初始化 TabBar 状态
    initTabBar()
  }, [initTabBar, setUserInfo])

  useDidShow(() => {})

  useDidHide(() => {})

  return <View className='app'>{props.children}</View>
}

export default App
